package com.zsyh.jiujiu.home;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.zyh.toolslib.base.BaseActivity;
import com.example.zyh.toolslib.utils.EmptyUtil;
import com.example.zyh.toolslib.utils.SPUtils;
import com.example.zyh.toolslib.widget.TitleBar;
import com.google.gson.Gson;
import com.lwb.retrofit.RetrofitTask;
import com.zsyh.jiujiu.Api;
import com.zsyh.jiujiu.R;
import com.zsyh.jiujiu.bean.MessageEvn;
import com.zsyh.jiujiu.bean.ZhuCeBean;
import com.zsyh.jiujiu.dialog.ClallBackData;
import com.zsyh.jiujiu.dialog.WuliuDialog;
import com.zsyh.jiujiu.net.MyObserver;
import com.zsyh.jiujiu.utils.ToastUtils;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import retrofit2.http.Query;

/**
 * @ProjectName: livvehelp
 * @Package: com.zsyh.lsb.ui
 * @ClassName:
 * @Description: java类作用描述
 * @Author: zsyh
 * @CreateDate: 2020/9/7 11:59
 * @UpdateUser: liangwanbo
 * @UpdateDate: 2020/9/7 11:59
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class WuliuActtivity extends BaseActivity {

    @BindView(R.id.title_bar)
    TitleBar titleBar;
    @BindView(R.id.ttv_danhao)
    TextView ttvDanhao;
    @BindView(R.id.danhao)
    EditText danhao;
    @BindView(R.id.tv_gongsi)
    TextView tvGongsi;
    @BindView(R.id.gongsi)
    TextView gongsi;
    @BindView(R.id.regongsi)
    RelativeLayout regongsi;
    @BindView(R.id.queeding)
    TextView queeding;
    private String orderid,userid;
    private String wuliuid,wuliubianma;

    @Override
    protected int initLayout() {
        return R.layout.acttivitty_wuliu;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        orderid=getIntent().getStringExtra("id");
        userid=(String) SPUtils.get(thisActivity, "userid", "");
    }

    @Override
    protected void initEvent() {
        titleBar.setLeftLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }



    @OnClick({R.id.regongsi, R.id.queeding})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.regongsi:

                WuliuDialog wuliuDialog=new WuliuDialog();
                wuliuDialog.setSelectAddresFinish(new ClallBackData() {
                    @Override
                    public void getData(String data, String name, String number) {
                        wuliubianma=data;
                        wuliuid=name;
                        gongsi.setText(data);
                    }
                });
                wuliuDialog.show(getSupportFragmentManager(),"");
                break;
            case R.id.queeding:
                if(EmptyUtil.isEmpty(danhao.getText().toString())){
                    com.zsyh.jiujiu.utils.ToastUtils.showShort(thisActivity,"填写物流单号");
                    return;
                }
                if(EmptyUtil.isEmpty(wuliubianma)){
                    ToastUtils.showShort(thisActivity,"选择物流");
                    return;
                }
                wuliu(userid,orderid,danhao.getText().toString(),wuliubianma,wuliuid);
                break;
        }
    }

    /**
     *
     */
    public void wuliu(String userId,
                      String orderId,
                      String trackno,
                      String trackname,
                      String tracknameCode){
        RetrofitTask.getInstance()
                .createApi(Api.class)
                .saveCourier( userId,
                         orderId,
                         trackno,
                         trackname,
                         tracknameCode)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new MyObserver(this,true) {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(String JsonStr) {
                        EventBus.getDefault().post(new MessageEvn("message", "all"));
                        thisActivity.finish();



                    }
                });

    }
}
